package reader

import (
	"bytes"
	"errors"
	"io"
	"io/ioutil"
	"worm/base"
	"worm/pool"
)

type multiReader struct {
	data []byte
}

func NewMultiReader(reader io.Reader) (pool.MultipleReader, error) {
	var data []byte
	var err error

	if reader != nil {
		data, err = ioutil.ReadAll(reader)
		if err != nil {
			return nil, errors.New(string(base.IOREADER_ERROR))
		}
	} else {
		data = []byte{}
	}
	return &multiReader{
		data: data,
	}, nil
}

func (r *multiReader) Reader() io.ReadCloser {
	return ioutil.NopCloser(bytes.NewReader(r.data))
}
